package com.Action;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;

import com.Bean.wd_orderModel;
import com.Service.orderService;



@Controller
@RequestMapping("/order")
public class OrderAction {
	@Autowired
	private orderService service;
	
	 @InitBinder  
	 public void initBinder(WebDataBinder binder) {  
	     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");  
	     dateFormat.setLenient(false);  
	     binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); 
	 }
	
	
	@RequestMapping("/toList.do")
	public String getList(Model model,wd_orderModel bean){
    System.out.println("1");
		List<wd_orderModel> list = service.getList(bean);
		model.addAttribute("list", list);
		
		System.out.println("=================================================="+list);
//		System.out.println(model);
		return "listOrder";
	}
	
	@RequestMapping("/getList.do")
	public String selectList(Model model,wd_orderModel bean){
    System.out.println("2");
    if(bean.getName().equals("")){
    	bean.setName(null);
    }
		List<wd_orderModel> list = service.selectList(bean);
		model.addAttribute("list", list);
		model.addAttribute("name", bean.getName());
		System.out.println("++++++++++++++++++++++++++++++"+list);
//		System.out.println(model);
		return "listOrder";
	}
	
	@RequestMapping("/toAdd.do")
	private String toAdd(){
		return "addOrder";
	}
    
	@RequestMapping("/add.do")
	private String Add(wd_orderModel record){
		int i=service.insert(record);
		//System.out.println(i);
		return "redirect:toList.do";
	}
	
	@RequestMapping("/delete.do")
	public String delete(String orderId){
		int i = service.deleteByPrimaryKey(orderId);
		//System.out.println(i+"kkkkkkkkkk");
		return "redirect:toList.do";
	}
	
	@RequestMapping("/toUpdate.do")
	public String toUpdate(String orderId,Model model){
		wd_orderModel bean = service.selectByPrimaryKey(orderId);
		model.addAttribute("order", bean);
		System.out.println("22222222"+bean);
		return "updateOrder";
	}
	
	@RequestMapping("/update.do")
	public String update(wd_orderModel bean){
		if(bean==null){
			System.out.println("kong#######################");
		}else{
		System.out.println("1111111111"+bean);
		int i = service.updateByPrimaryKey(bean);
		
		System.out.println("wwwwwwwwwww"+i);
		}
		return "redirect:toList.do";
	}
	
	
}